package com.anyou.mall.goo.goods.controller;

import com.anyou.common.annotation.Log;
import com.anyou.common.annotation.ShopScope;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.core.page.TableDataInfo;
import com.anyou.common.enums.BusinessType;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.mall.goo.goods.domain.GooGoods;
import com.anyou.mall.goo.goods.domain.JfDraw;
import com.anyou.mall.goo.goods.dto.GoodsAddDTO;
import com.anyou.mall.goo.goods.dto.GoodsEditDTO;
import com.anyou.mall.goo.goods.dto.GoodsIntegralListDTO;
import com.anyou.mall.goo.goods.dto.IntegralDrawDTO;
import com.anyou.mall.goo.goods.service.IGooGoodsService;
import com.anyou.mall.help.domain.HelpDocument;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 商品Controller
 *
 * @author ruoyi
 * @date 2022-03-24
 */
@Api(tags = "积分商品")
@RestController
@RequestMapping("/goods/goodsList")
public class GooGoodsController extends BaseController
{
    @Autowired
    private IGooGoodsService gooGoodsService;

    /**
     * 查询商品列表
     */
    /*@ApiOperation("查询商品列表")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:list')")
    @GetMapping("/list")
    @ShopScope(baseTableAlias="a")
    public TableDataInfo<List<GooGoods>> list(GooGoods gooGoods)
    {
        startPage();
        List<GooGoods> list = gooGoodsService.selectGooGoodsList(gooGoods);
        return getDataTable(list);
    }*/

    /**
     * 查询商品列表
     */
    @ApiOperation("查询积分商品列表")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:integralList')")
    @GetMapping("/integralList")
    @ShopScope(baseTableAlias="a")
    public TableDataInfo<List<GooGoods>> integralList(GoodsIntegralListDTO gooGoods)
    {
        startPage();
        List<GooGoods> list = gooGoodsService.selectGooGoodsIntegralList(gooGoods);
        return getDataTable(list);
    }

    /**
     * 导出商品列表
     */
    @ApiOperation("导出商品列表")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:export')")
    @Log(title = "商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ShopScope(baseTableAlias="a")
    public void export( GooGoods gooGoods,HttpServletResponse response)
    {
        List<GooGoods> list = gooGoodsService.selectGooGoodsList(gooGoods);
        ExcelUtil<GooGoods> util = new ExcelUtil<GooGoods>(GooGoods.class);
        util.exportExcel(response, list, "商品数据");
    }

    /**
     * 获取商品详细信息
     */
    /*@ApiOperation("获取商品详细信息")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:query')")
    @GetMapping(value = "/{goodsId}")
    public ApiResult<GooGoods> getInfo(@PathVariable("goodsId") Long goodsId)
    {
        return gooGoodsService.selectGooGoodsByGoodsId(goodsId);
    }*/

    /**
     * 新增商品
     */
    /*@ApiOperation("新增商品")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:add')")
    @Log(title = "商品", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@Valid @RequestBody GoodsAddDTO goodsAddDTO)
    {
        return gooGoodsService.insertGooGoods(goodsAddDTO);
    }*/

    /**
     * 修改商品
     */
    /*@ApiOperation("修改商品")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:edit')")
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@Valid @RequestBody GoodsEditDTO goodsEditDTO)
    {
        return gooGoodsService.updateGooGoods(goodsEditDTO);
    }*/

    /**
     * 删除商品
     */
    @ApiOperation("删除商品")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:remove')")
    @Log(title = "商品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{goodsIds}")
    public ApiResult remove(@PathVariable Long[] goodsIds)
    {
        return ApiResult.success(gooGoodsService.deleteGooGoodsByGoodsIds(goodsIds));
    }

    /**
     * 商品上下架
     */
    /*@ApiOperation("商品上下架 状态（0下架 1上架）")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:updatePublishStatus')")
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @PostMapping("/updatePublishStatus")
    public ApiResult updatePublishStatus(@RequestParam Long goodsId , @RequestParam String publishStatus)
    {
        return gooGoodsService.updatePublishStatus(goodsId,publishStatus);
    }*/

    /**
     * 商品app首页推荐
     */
    @ApiOperation("商品app首页推荐 状态（0不推荐 1推荐）")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:updateAppIndexStatus')")
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @PostMapping("/updateAppIndexStatus")
    public ApiResult updateAppIndexStatus(@RequestParam Long goodsId , @RequestParam String appIndexStatus)
    {
        return gooGoodsService.updateAppIndexStatus(goodsId,appIndexStatus);
    }

    /**
     * 商品app店铺首页推荐
     */
    /*@ApiOperation("商品app店铺首页推荐 状态（0不推荐 1推荐）")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:updateStoreIndexStatus')")
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @PostMapping("/updateStoreIndexStatus")
    public ApiResult updateStoreIndexStatus(@RequestParam Long goodsId , @RequestParam String storeIndexStatus)
    {
        return gooGoodsService.updateStoreIndexStatus(goodsId,storeIndexStatus);
    }*/

    @ApiOperation("违规上下架 状态（0正常 1违规下架）")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:updateViolationStatus')")
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @PostMapping("/updateViolationStatus")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", dataType = "Long", required = true, value = "商品编号"),
            @ApiImplicitParam(name = "violationStatus", dataType = "String", required = true, value = "上架状态（0下架 1上架）"),
            @ApiImplicitParam(name = "remark", dataType = "String", required = false, value = "上下架备注")
    })
    public ApiResult updateViolationStatus(@RequestParam Long goodsId , @RequestParam String violationStatus, @RequestParam(value = "remark", required = false) String remark)
    {
        return gooGoodsService.updateViolationStatus(goodsId,violationStatus,remark);
    }

    /**
     * 获取积分规则
     */
    @ApiOperation("获取积分规则")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:getIntegralRule')")
    @GetMapping(value = "/getIntegralRule")
    public ApiResult<HelpDocument> getIntegralRule()
    {
        return ApiResult.success(gooGoodsService.getIntegralRule());
    }

    /**
     * 编辑积分规则
     */
    @ApiOperation("编辑积分规则")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:editIntegralRule')")
    @PostMapping(value = "/editIntegralRule")
    public ApiResult editIntegralRule(@RequestBody HelpDocument helpDocument)
    {
        return ApiResult.success(gooGoodsService.editIntegralRule(helpDocument));
    }

    /**
     * 获取积分抽奖规则
     */
    @ApiOperation("获取积分抽奖规则")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:getIntegralDrawRule')")
    @GetMapping(value = "/getIntegralDrawRule")
    public ApiResult<HelpDocument> getIntegralDrawRule()
    {
        return ApiResult.success(gooGoodsService.getIntegralDrawRule());
    }

    /**
     * 编辑积分抽奖规则
     */
    @ApiOperation("编辑积分抽奖规则")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:editIntegralDrawRule')")
    @PostMapping(value = "/editIntegralDrawRule")
    public ApiResult editIntegralDrawRule(@RequestBody HelpDocument helpDocument)
    {
        return ApiResult.success(gooGoodsService.editIntegralDrawRule(helpDocument));
    }

    /**
     * 获取积分抽奖设置
     */
    @ApiOperation("获取积分抽奖设置")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:getIntegralDraw')")
    @GetMapping(value = "/getIntegralDraw")
    public ApiResult<List<JfDraw>> getIntegralDraw()
    {
        return ApiResult.success(gooGoodsService.getIntegralDraw());
    }

    /**
     * 编辑积分抽奖设置
     */
    @ApiOperation("编辑积分抽奖设置")
    @PreAuthorize("@ss.hasPermi('goods:goodsList:editIntegralRule')")
    @PostMapping(value = "/editIntegralDraw")
    public ApiResult editIntegralDraw(@Valid @RequestBody IntegralDrawDTO integralDrawDTO)
    {
        return ApiResult.success(gooGoodsService.editIntegralDraw(integralDrawDTO));
    }
}
